require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        layui.use(['form', 'laydate', 'upload'], function () {
            var upload = layui.upload;
            var uploadInst = upload.render({
                elem: '#uploads' //绑定元素
                , url: configPro.server_img_interface //上传接口
                , done: function (res) {
                    dic.thatNew.icon = configPro.server_img_view + res.data;
                }
                , error: function (res) {
                    alr("上传失败");
                }
                , accept: 'file'
            });
        });
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                type:"",
                that: {
                    carousel: [
                        {
                            title: "",
                            icon: "",
                            href: ""
                        }
                    ],
                    navigation: [
                        {
                            title: "",
                            icon: "",
                            href: ""
                        }
                    ],
                    plate: [
                        {
                            title: "",
                            icon: "",
                            href: ""
                        }
                    ]
                },
                thatNew: {
                    title: "",
                    icon: "",
                    href: ""
                }
            }
            , created: function () {
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    this.that = JSON.parse(playGet("service-shop/v1/index", "", "").data);
                },
                delNote: function () {
                    dic.thatNew.icon = "";
                },
                openAdd: function (it) {
                    dic.type=it;
                    alrYN($("#admins"), function () {
                        var jon = dic.that;
                        jon[it].push(dic.thatNew)
                        var re = playPost("service-shop/v1/index", "", JSON.stringify(jon));
                        alr(re.msg);
                    }, function () {

                    }, function () {

                    }, "新增商品", 1, ["900px", "300px"]);
                },
                updateAdd: function (it, index) {
                    dic.type=it;
                    var jon = dic.that;
                    dic.thatNew = jon[it][index];
                    alrYN($("#admins"), function () {
                        var jon = dic.that;
                        jon[it][index] = dic.thatNew;
                        var re = playPost("service-shop/v1/index", "", JSON.stringify(jon));
                        alr(re.msg);
                    }, function () {

                    }, function () {

                    }, "新增商品", 1, ["900px", "300px"]);
                },
                deleteNote:function(it,i){
                    var jon = dic.that;
                    jon[it].splice(i, 1);
                    dic.that=jon;
                    var re = playPost("service-shop/v1/index", "", JSON.stringify(jon));
                    alr(re.msg);
                }
            }
        });
    })
});